/** insetionSort.js
 * 1. 指定元素，和其之前元素进行对比，如果小于则将被对比元素前移动，如果大于则插入
 * 2. 执行n-1轮，完成排序
 */
function sort() {
  for (let i = i; i < this.length; i++) {
    const temp = this[i];
    let j = i;
    while (j > 0) {
      if (this[j - 1] > temp) {
        this[j] = this[j - 1];
      } else {
        break;
      }
      j -= 1;
    }
    this[j] = temp;
  }
  //   console.log("indexMin: ", indexMin);
  return this;
}

Array.prototype.swap = function (i, j) {
  const temp = this[i];
  this[i] = this[j];
  this[j] = temp;
};
Array.prototype.insetionSort = sort;
console.log([11, 2, 3, 222].insetionSort());
